"""
@name : Linux用户管理类
@author : maxueyan
@projectname: sanchuang
"""

import subprocess
import os

#基类，往Linux系统里面添加用户
class S():
    def add_user(self):
        username = input("请输入用户名：")
        os.system(f"useradd {username}")
        print("创建成功")

#查看、修改uid、gid和shell等
class A(S):
    def cat_msg(self):
        username = input("请输入你要查询的用户名：")
        print(os.system(f"id {username}"))

    def mod_uid(self):
        username = input("请输入用户名：")
        uid = input("请输入需要修改的UID号：")
        os.system(f"usermod -u {uid} {username} ")
        print("修改成功")

    def mod_gid(self):
        username = input("请输入用户名：")
        gid = input("请输入需要修改的GID号：")
        os.system(f"usermod -g {gid} {username} ")
        print("修改成功")

class B(S):
    def del_user(self):
        username = input("请输入用户名：")
        os.system(f"userdel -r {username}")
        print("删除成功")

    def del_group(self):
        groupname = input("请输入组名：")
        os.system(f"groupdel {groupname}")

class C(A,B):
    def __init__(self):
        self.groupname = input("请输入组名：")
        self.groupid = input("请输入组号：")
        os.system(f"groupadd -g {self.groupid} {self.groupname}")

    def change_gid(self):
        username = input("请输入用户名：")
        os.system(f"usermod -g {self.groupid} {username}")

class Name_error(Exception):
    def __str__(self):
        return "sorry Name is error"
while True:
    print('''
    1、添加用户
    2、查看用户信息
    3、修改UID
    4、修改GID
    5、删除用户
    6、删除组
    7、新建组
    8、改变原有GID
    9、退出
    ''')
    choose = int(input("请输入你的选择："))
    if 1 <= choose <= 9:
        if choose == "1":
            a = S.add_user()
        if choose == "2":
            a = A.cat_msg()
        if choose == "3":
            a = A.mod_uid()
        if choose == "4":
            a = A.mod_gid()
        if choose == "5":
            a = B.del_user()
        if choose == "6":
            a = B.del_group()
        if choose == "7":
            a = C.__init__()
        if choose == "8":
            a = C.change_gid()
        if choose == "9":
            exit()
    else:
        print("请输入数字1-9")


